package com.hongyi.app.util;


import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;
import org.omg.CORBA.portable.ValueOutputStream;

/**
 * @author HongYi
 */
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Result {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 描述信息
     */
    private String message;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 操作成功，返回固定的响应码、描述信息,无响应数据
     *
     * @return
     */
    @SneakyThrows
    public static Result ok() {
        return new Result(1, "success", null);
    }

    /**
     * 操作成功，返回固定的响应码、描述信息,自定义响应数据
     *
     * @param data
     * @return
     */
    @SneakyThrows
    public static Result ok(Object data) {
        return new Result(1, "success", data);
    }

    /**
     * 操作成功，返回自定义的响应码和描述信息,无响应数据
     *
     * @return
     */
    @SneakyThrows
    public static Result ok(Integer code, String message) {
        return new Result(code, message, null);
    }

    /**
     * 操作成功，返回自定义的响应码、描述信息和响应数据
     *
     * @param code
     * @param message
     * @param data
     * @return
     */
    @SneakyThrows
    public static Result ok(Integer code, String message, Object data) {

        return new Result(code, message, data);
    }


    /**
     *
     * @return
     */
   @SneakyThrows
   public static Result fail(){
        return new Result(-1,"fail",null);
   }

   @SneakyThrows
   public static Result fail(Object data){
       return new Result(-1,"fail",data);
   }
    /**
     *操作失败，返回自定义的响应码
     * @param code
     * @param message
     * @return
     */
    @SneakyThrows
    public static Result fail(Integer code, String message) {
        return new Result(code,message,null);
    }

}
